package com.geek.aop;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

@Slf4j
public class Main {
    public static void main(String[] args) {

        try (AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(AopConfig.class)) {
            DemoAnnotationService demoAnnotationService = annotationConfigApplicationContext.getBean(DemoAnnotationService.class);
            DemoMethodService demoMethodService = annotationConfigApplicationContext.getBean(DemoMethodService.class);
            demoAnnotationService.add();
            demoMethodService.add();
        }

        try (AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(ScopeConfig.class)) {
            DemoAnnotationService demoAnnotationService1 = annotationConfigApplicationContext.getBean(DemoAnnotationService.class);
            DemoAnnotationService demoAnnotationService2 = annotationConfigApplicationContext.getBean(DemoAnnotationService.class);
            DemoMethodService demoMethodService1 = annotationConfigApplicationContext.getBean(DemoMethodService.class);
            DemoMethodService demoMethodService2 = annotationConfigApplicationContext.getBean(DemoMethodService.class);
            log.info("demoAnnotationService1 == demoAnnotationService2  " + (demoAnnotationService1 == demoAnnotationService2));
            log.info("demoMethodService1 == demoMethodService2  " + (demoMethodService1 == demoMethodService2));
        }

        try (AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(ELConfig.class)) {
            ELConfig elConfig = annotationConfigApplicationContext.getBean(ELConfig.class);
            elConfig.outputResource();
        }

        try (AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(PrePostConfig.class)) {
            BeanWayService beanWayService = annotationConfigApplicationContext.getBean(BeanWayService.class);
            JSR250WayService jsr250WayService = annotationConfigApplicationContext.getBean(JSR250WayService.class);
        }

        try (AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext()) {
            annotationConfigApplicationContext.getEnvironment().setActiveProfiles("production");
            annotationConfigApplicationContext.register(ProfileConfig.class);
            annotationConfigApplicationContext.refresh();

            DemoBean demoBean = annotationConfigApplicationContext.getBean(DemoBean.class);
            log.info("Profile : {}", demoBean.getContent());
        }
    }
}
